<template>
  <a-card :bordered="false">
    <!-- 左侧面板 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="7" :sm="8">
            <a-form-item label="活动名称" :labelCol="{ span: 6 }" :wrapperCol="{ span: 14, offset: 1 }">
              <a-input placeholder="活动名称" v-model="queryParam.title"></a-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="活动状态">
              <a-select v-model="queryParam.status" placeholder="请选择活动状态">
                <a-select-option v-for="(item, index) in dictOptions" :key="index.toString()" :value="item.value">
                  {{ item.label }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="7" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>

      <div class="table-operator" style="border-top: 5px">
        <a-button @click="handleAdd" type="primary" icon="plus">添加</a-button>
        <!-- <a-button type="primary" icon="hdd" @click="openDeleteList">回收站</a-button> -->
      </div>

      <a-table
        ref="table"
        rowKey="id"
        size="middle"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <img slot="pic" slot-scope="text" style="width: 100px; height: 50px" :src="text" />

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">
            <a-icon type="edit" />
            编辑
          </a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>

    <activity-model ref="modalForm" @ok="modalFormOk"></activity-model>
  </a-card>
</template>

<script>
import ActivityModel from './modules/ActivityModel'
// import DictDeleteList from './DictDeleteList'
import { BasePostMixin } from '@/mixins/BasePostMixin'
import { filterObj } from '@/utils/util'
import { ajaxGetDictItems } from '@api/api'
export default {
  name: 'activityList',
  mixins: [BasePostMixin],
  components: {
    ActivityModel,
  },
  data() {
    return {
      dictOptions: [],
      // 查询条件
      queryParam: {
        dictCode: '',
        dictName: '',
      },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 120,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '活动名称',
          align: 'left',
          dataIndex: 'title',
          customRender: (text, record) => (
            <a-tooltip placement="topLeft" title={text}>
              {text}
            </a-tooltip>
          ),
        },
        {
          title: '活动内容',
          align: 'left',
          dataIndex: 'actName',
          ellipsis: true,
          customRender: (text, record) => (
            <a-tooltip placement="topLeft" title={text}>
              {text}
            </a-tooltip>
          ),
        },
        {
          title: '价格',
          align: 'left',
          dataIndex: 'price',
          width: 120,
          customRender: function (t) {
            return t + '元'
          },
        },
        {
          title: '基地',
          align: 'left',
          dataIndex: 'shopName',
          ellipsis: true,
          width: 120,
          customRender: (text, record) => (
            <a-tooltip placement="topLeft" title={text}>
              {text}
            </a-tooltip>
          ),
        },
        {
          title: '城市',
          align: 'left',
          dataIndex: 'city',
          width: 120,
        },
        {
          title: '地址',
          align: 'left',
          dataIndex: 'address',
          ellipsis: true,
          customRender: (text, record) => (
            <a-tooltip placement="topLeft" title={text}>
              {text}
            </a-tooltip>
          ),
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/wx/activity/list',
        delete: '/wx/activity/delete',
      },
    }
  },
  created() {
    this.getDictItem()
  },
  methods: {
    getQueryParams() {
      var param = Object.assign({}, this.queryParam, this.isorter)
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
        param['superQueryMatchType'] = this.superQueryMatchType
      }
      return filterObj(param)
    },
    getDictItem() {
      //根据字典Code, 初始化字典数组
      ajaxGetDictItems('activity_status', null).then((res) => {
        if (res.code === 20000) {
          this.dictOptions = res.data
        }
      })
    },
  },
}
</script>

<style scoped>
</style>